<template>
  <div id="support">
    <div class="body">
      <div class="title">
        <span>4<i style="opacity: .5;">/4</i></span>
        <span>
          <van-icon name="records-o" size="22" color="#1989fa;"/>&nbsp;假肢服务与支持
        </span>
      </div>
      <van-divider />
      <form>
        <div class="one">
          <h3>
            <span class="iconfont icon-bitian" style="color: #ec6661;"></span>
            <i style="opacity: .5;">[单选题]</i>
            您对目前的假肢服务与支持满意吗?
            <van-tag type="warning" v-if="message[0].bool">您未完成此项</van-tag>
          </h3>
          <van-radio-group v-model="message[0].data" class="one-radio-group">
            <van-radio name="1">非常满意</van-radio>
            <van-radio name="2">比较满意</van-radio>
            <van-radio name="3">一般</van-radio>
            <van-radio name="4">不太满意</van-radio>
            <van-radio name="5">非常不满意</van-radio>
          </van-radio-group>
        </div>
        <div class="two">
          <h3>
            <span class="iconfont icon-bitian" style="color: #ec6661;"></span>
            <i style="opacity: .5;">[多选题]</i>
            您希望获得哪些方面的假肢服务与支持?
            <van-tag type="warning" v-if="message[1].bool">您未完成此项</van-tag>
          </h3>
          <van-checkbox-group v-model="message[1].data">
            <van-checkbox name="1" shape="square">假肢适配与调试</van-checkbox>
            <van-checkbox name="2" shape="square">假肢使用培训与指导</van-checkbox>
            <van-checkbox name="3" shape="square">假肢维修与保养</van-checkbox>
            <van-checkbox name="4" shape="square">心理支持与咨询服务</van-checkbox>
            <van-checkbox name="5" shape="square">其他</van-checkbox>
          </van-checkbox-group>
        </div>
        <div class="three">
          <h3>
            <span class="iconfont icon-bitian" style="color: #ec6661;"></span>
            <i style="opacity: .5;">[开放性问题]</i>
            您对假肢有哪些其他的建议或意见?
            <van-tag type="warning" v-if="message[2].bool">您未完成此选项</van-tag>
          </h3>
          <van-field
              v-model="message[2].data"
              rows="2"
              autosize
              type="textarea"
              maxlength="200"
              placeholder="请输入您的建议或意见"
              show-word-limit
              style="
              border: 1px solid rgba(0, 0, 0,.6);
              "
              />
        </div>
        <div class="four">
          <h3>
            <span class="iconfont icon-bitian" style="color: #ec6661;"></span>
            <i style="opacity: .5;">[开放性问题]</i>
            您认为社会应该如何更好地支持残疾人使用假肢?
            <van-tag type="warning" v-if="message[3].bool">您未完成此选项</van-tag>
          </h3>
          <van-field
              v-model="message[3].data"
              rows="2"
              autosize
              type="textarea"
              maxlength="200"
              placeholder="请输入您的建议或意见"
              show-word-limit
              style="
              border: 1px solid rgba(0, 0, 0,.6);
              "
              />
        </div>
      </form>
    </div>
    <div class="tapBar">
      <div class="tapBarBox" style="border-right: 1px solid rgba(0, 0, 0,.2);color: #1989fa;">
          <button @click="$router.back()">上一页</button>
        </div>
      <div class="tapBarBox">
        <button :disabled="isdisabled" @click="skip" type="buttom">提交</button>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'supportPage',
  data () {
    return {
      message: [
        { data: '', bool: false },
        { data: [], bool: false },
        { data: '', bool: false },
        { data: '', bool: false }
      ],
      isSkip: [],
      isdisabled: false,
      timer: null
    }
  },
  methods: {
    skip () {
      this.isSkip = JSON.parse(localStorage.getItem('demand'))
      if (this.isSkip === null) {
        this.message.forEach(item => {
          item.bool = true
        })
        this.isdisabled = true
        this.timer = setTimeout(() => {
          this.message.forEach(item => {
            item.bool = false
          })
          this.isdisabled = false
        }, 2000)
        return
      }

      if (this.message.find((item) => item.data.length === 0)) {
        this.isdisabled = true
        this.message.forEach(item => {
          if (item.data.length === 0) {
            item.bool = true
          }
        })

        this.timer = setTimeout(() => {
          this.message.forEach(item => {
            item.bool = false
          })
          this.isdisabled = false
        }, 2000)
        return
      }
      this.$toast.success('提交成功')
      this.timer = setTimeout(() => {
        this.$router.push('/frame/home')
      }, 2000)
    }
  },
  created () {
    if (localStorage.getItem('support')) this.message = JSON.parse(localStorage.getItem('support'))
  },
  watch: {
    message: {
      deep: true,
      handler (newVal) {
        localStorage.setItem('support', JSON.stringify(newVal))
      }
    }
  }
}
</script>

<style scoped>
  .one-radio-group{
    padding: 0 20px;
  }
</style>
